package com.xinxin.datastructure.stack.impl;

import com.xinxin.datastructure.linkedlist.LinkedList;
import com.xinxin.datastructure.stack.Stack;

/**
 * @author ：史鑫鑫
 * @date ：Created in 2019/4/24 15:32
 */
public class LinkedListStack<E> implements Stack<E> {
    private LinkedList<E> linkedList;

    public LinkedListStack() {
        linkedList = new LinkedList<E>();
    }

    @Override
    public void push(E e) {
        linkedList.addFirst(e);
    }

    @Override
    public E pop() {
        return linkedList.removeFirst();
    }

    @Override
    public E peek() {
        return linkedList.getFirst();
    }

    @Override
    public int getSize() {
        return linkedList.getSize();
    }

    @Override
    public boolean isEmpty() {
        return linkedList.isEmpty();
    }

    @Override
    public String toString() {
        return "Stack: top " + linkedList;
    }
}
